package com.yxw.live_vod_backend_boot.controller;

import com.yxw.live_vod_backend_boot.dto.ProductCategoryDTO;
import com.yxw.live_vod_backend_boot.dto.ProductCategoryQueryDTO;
import com.yxw.live_vod_backend_boot.dto.ProductCategoryUpdateDTO;
import com.yxw.live_vod_backend_boot.service.ProductCategoryService;
import com.yxw.live_vod_backend_boot.vo.ProductCategoryVO;
import com.yxw.yxnet_cd_center.common.dto.PageVO;
import com.yxw.yxnet_cd_center.common.helper.ResultHelper;
import com.yxw.yxnet_cd_center.common.utils.BaseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 商品类目管理 Controller控制层
 *
 * @author xiexuxin
 * @date 2023-12-06
 */
@RestController
@Api(value = "商品类目管理", tags = "商品类目管理")
@Slf4j
@RequestMapping("/api/product_category")
public class ProductCategoryController {

    @Autowired
    private ProductCategoryService categoryService;

    @ApiOperation("添加商品类目")
    @PostMapping("add_category")
    public BaseResult addCategory(@RequestBody @Validated ProductCategoryDTO categoryDTO) {
        categoryService.addCategory(categoryDTO);
        return BaseResult.doSuccess(null, "添加成功");
    }

    @ApiOperation("修改商品类目")
    @PostMapping("update_category")
    public BaseResult updateCategory(@RequestBody @Validated ProductCategoryUpdateDTO categoryDTO) {
        categoryService.updateCategory(categoryDTO);
        return BaseResult.doSuccess(null, "修改成功");
    }

    @ApiOperation("获取商品类目列表")
    @PostMapping("get_category_list")
    public BaseResult<PageVO<ProductCategoryVO>> getCategoryList(@RequestBody @Validated ProductCategoryQueryDTO queryDTO) {
        PageVO<ProductCategoryVO> pageVO = categoryService.getCategoryList(queryDTO);
        return ResultHelper.fillWithSuccess(pageVO);
    }

    @ApiOperation("获取商品类目详情")
    @PostMapping("get_category_by_id")
    public BaseResult getCategoryById(@RequestParam("categoryId") String categoryId) {
        ProductCategoryVO categoryVO = categoryService.getCategoryById(categoryId);
        return BaseResult.doSuccess(categoryVO,"查询成功");
    }

    @ApiOperation("商品类目启用/禁用")
    @PostMapping("is_enable_category_by_id")
    public BaseResult isEnableCategoryById(@RequestParam("categoryId") String categoryId) {
        categoryService.isEnableCategoryById(categoryId);
        return BaseResult.doSuccess(null, "设置成功");
    }

}
